package com.jason.system.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jason.system.common.util.Pager;
import com.jason.system.common.util.RedisUtil;
import com.jason.system.entity.Student;
import com.jason.system.mapper.StudentMapper;
import com.jason.system.service.StudentService;
import io.swagger.models.auth.In;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jie
 * @version 1.0
 * success come from self-discipline
 * @date 2021/3/25 15:31
 */
@Service
public class StudentServiceImpl implements StudentService {

  private static final Logger logger = LoggerFactory.getLogger(Logger.class);

  @Resource
  StudentMapper studentMapper;

  @Autowired
  RedisUtil redisUtil;

  @Override
  public Pager<Student> getAllStudent(Integer page , Integer size) {
    PageHelper.startPage(page,size);
    List<Student> students = studentMapper.getAllStudent();
    PageInfo<Student> studentPageInfo = new PageInfo<>(students);
    return new Pager<>(studentPageInfo);
  }

  @Override
  public Pager<Student> searchStudents(Integer page, Integer size, String grade, String major) {
    PageHelper.startPage(page,size);
    List<Student> students = studentMapper.searchStudents(grade,major);
    PageInfo<Student> studentPageInfo = new PageInfo<>(students);
    return new Pager<>(studentPageInfo);
  }

  @Override
  public List<Student> getAllStudent() {
    return studentMapper.getAllStudent();
  }

  @Override
  public Student getStudentByNo(String stuNo) {
    if("".equals(stuNo) || stuNo==null){
      return null;
    }
    return studentMapper.getStudentByNo(stuNo);
  }

  @Override
  public void insertStudent(Student student) {
    studentMapper.insertStudent(student);
  }

  @Override
  public void updateStudent(Student student) {
    studentMapper.updateStudent(student);
  }

  @Override
  public boolean deleteStudent(Integer stuId) {
    if (stuId==null){
      return false;
    }else {
      studentMapper.deleteStudent(stuId);
      return true;
    }
  }

  @Override
  public boolean deleteMoreStudent(List<Integer> studentIds) {
    if (studentIds==null){
      return false;
    }else {
      studentMapper.deleteMoreStudent(studentIds);
      return true;
    }
  }
}
